{% extends "base_logged.html" %}

{% block page %}
<div id="page-wrapper">

  <div class="row">
    <div class="col-lg-12">
      <h1>Jobs templates</h1>
      <ol class="breadcrumb">
        <li><a href="{{ url_for('index') }}"><i class="fa fa-dashboard"></i> SaltPad</a></li>
        <li class="active"><i class="fa fa-magic"></i> Templates</li>
      </ol>
    </div>
  </div><!-- /.row -->

  <div class="alert alert-warning" role="alert">Jobs templates are saved in salt-master configuration and adding a new template will change the salt-master configuration formatting and will strip comments. See <a href="http://docs.saltstack.com/en/latest/ref/wheel/all/salt.wheel.config.html#salt.wheel.config.apply">the documentation for more details.</a></div>

<div class="row">
  <div class="col-lg-12">
    <h2>Templates <a href="{{ url_for('add_template') }}"><button type="button" class="btn btn-info">Add a template</button></a></h2>
    <div class="table-responsive">
      <table class="table table-bordered table-hover tablesorter" id="minions">
        <thead>
          <tr>
            <th>Template name</i></th>
            <th>Description</i></th>
            <th>Target</th>
            <th>Function</th>
            <th>Latest runs</th>
            <th>Launch template job</i></th>
          </tr>
        </thead>
        <tbody>
          {% for template_name, template in templates.items() %}
          <td>{{ template_name }}</td>
          <td>{{ template.description }}</td>
          <td>{{ template.tgt }}</td>
          <td>{{ template.fun }}</td>
          <td></td>
          <td><a href="{{ url_for('run_template', template=template_name) }}">Launch now</a></td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  </div>
</div><!-- /.row -->
{% endblock %}

{% block scripts %}
<script type="text/javascript">
$(function() {
  $("#minions").dataTable({
    "order": [[0, "desc"]],
    "lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]],
    "columnDefs": [
      { "orderable": false, "targets": -1 }
    ]
  });
});
</script>
{% endblock %}
